<template>
	<div>
		<el-dialog title="复制添加" width="70%" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width="$store.getters.device !== 'mobile'?'16%':'90px'">
 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.LanguageField_code')" prop="code">
							<el-select style="width:100%" v-model="form.code" filterable clearable :placeholder="$t('system.pleaseSelect')">
								<el-option v-for="(item,i) in codes" :key="i" :label="item.key" :value="item.val.toString()"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
				   <el-col :span="24">
                        <el-form-item :label="$t('field.LanguageField_type')" prop="type">
                            <el-select style="width:100%" v-model="form.type" :size="size" clearable filterable :placeholder="$t('system.pleaseSelect')">
								<el-option key="0"  label="字符串" value="string"></el-option>
								<el-option key="1"  label="文本域" value="textarea"></el-option>
                                <el-option key="2"  label="富文本" value="richtext"></el-option>
                                <el-option key="3"  label="文件" value="file"></el-option>
                                <el-option key="4"  label="图片" value="image"></el-option>
                                <el-option key="5"  label="多图片" value="multimage"></el-option>
                            </el-select>
                        </el-form-item>
                   </el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.LanguageField_tip')" prop="tip">
							<el-input v-model="form.tip" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.LanguageField_tip')})"></el-input>
						</el-form-item>
					</el-col>
				 </el-row>
				 <el-row v-if="form.type=='string'">
					<el-col :span="24">
						<el-form-item :label="$t('field.LanguageField_content')" prop="content">
							<el-input v-model="form.content" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.LanguageField_content')})"></el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 			 <el-row v-if="form.type=='richtext'">
					<el-col :span="24">
						<el-form-item :label="$t('field.LanguageField_content')" prop="content">
							<TinymceEditor v-if="show" tinymceId="content"  :tinymceContent.sync="form.content"></TinymceEditor>
						</el-form-item>
					</el-col>
				 </el-row>
				 <el-row v-if="form.type=='image'">
					<el-col :span="24">
						<el-form-item :label="$t('field.LanguageField_content')" prop="content">
							<ImagesUpload size="small"  uploadType="2" fileType="image" :image.sync="form.content"></ImagesUpload>
						</el-form-item>
					</el-col>
				 </el-row>
				 <el-row v-if="form.type=='multimage'">
					<el-col :span="24">
						<el-form-item :label="$t('field.LanguageField_content')" prop="content">
							<ImagesUpload size="small"  fileType="images" :images.sync="form.content"></ImagesUpload>
						</el-form-item>
					</el-col>
				 </el-row>
	 			 <el-row v-if="form.type=='file'">
					<el-col :span="24">
						<el-form-item :label="$t('field.LanguageField_content')" prop="content">
							<ImagesUpload size="small" fileType="file"  :file.sync="form.content"></ImagesUpload>
						</el-form-item>
					</el-col>
				 </el-row>
				 <el-row v-if="form.type=='textarea'">
					<el-col :span="24">
						<el-form-item :label="$t('field.LanguageField_content')" prop="content">
							<el-input  type="textarea" autoComplete="off" v-model="form.content"  :autosize="{ minRows: 2, maxRows: 4}" clearable :placeholder="$t('system.pleaseInput',{title:$t('field.LanguageField_content')})"></el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 			<el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.LanguageField_extend')" prop="extend">
							<el-input v-model="form.extend" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.LanguageField_extend')})"></el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.LanguageField_remark')" prop="remark">
							<el-input v-model="form.remark" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.LanguageField_remark')})"></el-input>
						</el-form-item>
					</el-col>
				 </el-row>
				</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">{{$t('system.confirm')}}</span>
					<span v-else>{{$t('system.submitting')}}</span>
				</el-button>
				<el-button :size="size" @click="closeForm">{{$t('system.cancel')}}</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
import { clone, getFieldList } from '@/api/app/languagefield'
import ImagesUpload from '@/components/common/ImagesUpload.vue'
import TinymceEditor from '@/components/editor/TinymceEditor.vue'


export default {
	name:'languageFieldclone',
	components: {
	   		ImagesUpload,
	   		TinymceEditor,
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
        info:{
            type: Object,
        },		
	},
	data(){
		return {
			form: {
			   code:'',
			   type:'string',
			   tip:'',
			   content:'',
			   extend:'',
			   remark:'',
			},
			codes:[],
			loading:false,
			rules: {
			}
		}
	},
	watch:{
		show(val){
			if(val){
				getFieldList().then(res => {
					if(res.status == 200){
						this.codes = res.data.codes
					}
				})
			}
		}
	},
	methods: {
		open(){
		  this.form=this.info
          delete this.form.id
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					clone(this.form).then(res => {
						if(res.status == 200){
							this.$message({message: this.$t('system.success'), type: 'success'})
							this.$emit('refresh_list')
							this.closeForm()
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
}
</script>
<style scoped lang="scss">
@import '@/assets/scss/common.scss'
</style>
